//
//  RecurrenceRelations.cpp
//  MATH233_iLab3
//
//  Created by Ronald Ram on 1/27/13.
//  Copyright (c) 2013 Ronald Ram. All rights reserved.
//


#include "RecurrenceRelations.h"
#include <cmath>

#pragma mark CTOR-DTOR
RecurrenceRelations::~RecurrenceRelations()
{
    rr1.clear(); //clears array size = zero
    //creates a temp vector of Ints & guarantees allocate zero raw memory or implementation min.
    vector<int>().swap(rr1); //resets memry capacity = zero
    
    rr2.clear();
    vector<int>().swap(rr2);
}


#pragma mark GETTERs-SETTERs
//Getter/Setter for Input1
int RecurrenceRelations::getInput1() { return this->input1; }
void RecurrenceRelations::setInput1( int input )
{
    rr1.clear();
    rr2.clear();
    
    this->input1 = input;
    rr1.push_back(input1);
    rr2.push_back(input1);
}

//Getter/Setter for Input2
int RecurrenceRelations::getInput2() { return this->input2; }
void RecurrenceRelations::setInput2( int input )
{
    this->input2 = input;
    rr1.push_back(input2);
    rr2.push_back(input2);
}


#pragma mark RR1 METHODS
//STEP 1: An = 4An−1 − 4An−2; f(n) = (2)n; g(n) = (2.1)n
//        An = 4An−1 − 4An−2; f(n) = (2)n; g(n) = (2.1)n
void RecurrenceRelations::RR1()
{
    int a0, a1, result;
    
    for ( int i=2; i< 19; ++i)
    {
        a0 = rr1[i - 1];
        a1 = rr1[i-2];
        result = (4 * a0) - (4 * a1);
        
        rr1.push_back(result);
    }
}


#pragma mark RR2 METHODS
//STEP 2: An = −An−1 + An−2; f(n) = (1.5)n; g(n) = (1.8)n
//        An = −An−1 + An−2; f(n) = (1.5)n; g(n) = (1.8)n
void RecurrenceRelations::RR2()
{
    int a0, a1, result;
    
    for ( int i=2; i<19; ++i)
    {
        a0 = rr2[i - 1];
        a1 = rr2[i-2];
        result = (-a0) + (a1);
        
        rr2.push_back(result);
    }
}


#pragma mark PRIVATE METHODS
//1st & 2nd difference sequence
float RecurrenceRelations::difference( float value, float nTH )
{
    return pow(value, nTH);
}


#pragma mark PUBLIC METHODS
//Print results
void RecurrenceRelations::print()
{
    cout << "\n===================================================" << endl;
    cout << "\t\t\t RESULTS:" <<endl;
    cout << "===================================================\n" << endl;
    
    //PRINT: STEP 1 RESULTS
    cout << "n\t\t" << "A(n)=4A[n-1]-4A[n-2]" << "\t\t" << "2^n" << "\t\t\t" << "2.1^n" << endl;
    cout << "--------------------------------------------------------------" << endl;
    for ( int i=0; i < rr1.size(); ++i )
    {
        cout << "[" << i << "] = " << "\t" << rr1[i] << ",\t\t\t\t\t\t" << difference(2, i) << ",\t\t\t" << difference(2.1, i) << endl;
    }
    cout << "\n\n" << endl;
    
    //PRINT: STEP 2 RESULTS
    cout << "n\t\t" << "A(n)=-A[n-1]+A[n-2]" << "\t\t" << "1.5^n" << "\t\t\t" << "1.8^n" << endl;
    cout << "--------------------------------------------------------------" << endl;
    for ( int j=0; j < rr1.size(); ++j )
    {
        cout << "[" << j << "] = " << "\t" << rr2[j] << ",\t\t\t\t\t\t"  << difference(1.5, j) << ",\t\t\t\t " << difference(1.8, j) << endl;
    }
    cout << "\n\n" << endl;
}

